/*************************************************************************
 * File Name:    1698_bipartite.cc
 * Author:       zero91
 * Mail:         jianzhang9102@gmail.com
 * Created Time: Sun 20 Oct 2013 04:59:38 PM CST
 * 
 * Description:  http://poj.org/problem?id=1698
 * Solution:     Transform into a bipartite match problem
 *
 ************************************************************************/

#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <iomanip>

using namespace std;

#define MAXD 50
#define MAXW 50
#define MAXN 25
#define MATRIX_ROW (MAXD * MAXN)
#define MATRIX_COL 360

bool matrix[MATRIX_ROW][MATRIX_COL];
bool visited[MATRIX_COL];
int lnk[MATRIX_COL];

bool
dfs(int v, int max_col)
{
    for (int i = 0; i < max_col; ++i) {
        if (visited[i] || !matrix[v][i]) continue;
        visited[i] = true;
        if (lnk[i] == -1 || dfs(lnk[i], max_col)) {
            lnk[i] = v;
            return true;
        }
    }
    return false;
}

int
main(int argc, char *argv[])
{
    int T, N;
    int d, w, week[7];
    int row_cnt, ans, max_col;

    scanf("%d", &T);
    while (T--) {
        memset(matrix, false, sizeof(matrix));

        scanf("%d", &N);

        row_cnt = max_col = 0;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < 7; ++j) {
                scanf("%d", &week[j]);
            }
            scanf("%d %d", &d, &w);
            if (w * 7 > max_col) max_col = w * 7;

            for (int j = 0; j < 7; ++j) {
                if (week[j] == 0) continue;
                for (int s = 0; s < d; ++s) {
                    for (int t = 0; t < w; ++t) {
                        matrix[row_cnt + s][t * 7 + j] = true;
                    }
                }
            }
            row_cnt += d;
        }
        ans = 0;
        memset(lnk, -1, sizeof(lnk));
        for (int i = 0; i < row_cnt; ++i) {
            memset(visited, false, sizeof(visited));
            if (dfs(i, max_col)) ++ans;
        }
        if (ans == row_cnt) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}
